package com.sjq.common.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.sjq.common.dao.ApplicationSystemDao;
import com.sjq.common.dao.GenericDao;
import com.sjq.common.entity.ApplicationSystem;
/**
 * 应用系统信息 业务层接口实现
 * @author xc
 * @version 2018.02.08
 * @since jdk1.6
 *
 */
@Repository
public class ApplicationSystemDaoImpl extends GenericDao<ApplicationSystem> implements ApplicationSystemDao {

	@Override
	public List<ApplicationSystem> findAll() {
		String sql=" select xxzjbh,xtmc,zgbm_gajgmc,xtztdm,xxxtbbh,to_char(sxyxrq_rq,'yyyy-mm-dd') sxyxrq_rq,"
		+" yyxtfwdz, jbgn_jyqk,zrr_xm,yddh,chjidw_dwmc from T_PZ_SYS_SYSTEM ";
		List<ApplicationSystem> applicationSystemList =getList(sql);
		return applicationSystemList;
	}

	@Override
	public List<ApplicationSystem> findByLimit(int start,int end) {
		String sql=" select * from( select xxzjbh,xtmc,zgbm_gajgmc,xtztdm,xxxtbbh,to_char(sxyxrq_rq,'yyyy-mm-dd') sxyxrq_rq,"
				+" yyxtfwdz, jbgn_jyqk,zrr_xm,yddh,chjidw_dwmc,rownum row_num from T_PZ_SYS_SYSTEM ) "
				+"  where  row_num  between "+start+" and "+end;
		List<ApplicationSystem> applicationSystemList =getList(sql);		
		return applicationSystemList;
	}
	
	public List<ApplicationSystem> getList(String sql){
		List<ApplicationSystem> applicationSystemList = this.getJdbcTemplate().query(sql,  new RowMapper<ApplicationSystem>() {
            @Override
            public ApplicationSystem mapRow(ResultSet resultSet, int i) throws SQLException {
            	ApplicationSystem applicationSystem = new ApplicationSystem();
            	applicationSystem.setXxzjbh(resultSet.getString("xxzjbh"));
            	applicationSystem.setXtmc(resultSet.getString("xtmc"));
            	applicationSystem.setZgbm_gajgmc(resultSet.getString("zgbm_gajgmc"));
            	applicationSystem.setXtztdm(resultSet.getString("xtztdm"));
            	applicationSystem.setXxxtbbh(resultSet.getString("xxxtbbh"));
            	applicationSystem.setSxyxrq_rq(resultSet.getString("sxyxrq_rq"));
            	applicationSystem.setYyxtfwdz(resultSet.getString("yyxtfwdz"));
            	applicationSystem.setJbgn_jyqk(resultSet.getString("jbgn_jyqk"));
            	applicationSystem.setZrr_xm(resultSet.getString("zrr_xm"));
            	applicationSystem.setYddh(resultSet.getString("yddh"));
            	applicationSystem.setChjidw_dwmc(resultSet.getString("chjidw_dwmc"));
                return applicationSystem;
            }
        });
		return applicationSystemList;
	}
	
	@Override
	public List<ApplicationSystem> find(ApplicationSystem sys) {
		String sql=	" select xxzjbh,xtmc,zgbm_gajgmc,xtztdm,xxxtbbh,to_char(sxyxrq_rq,'yyyy-mm-dd') sxyxrq_rq,"+
				" yyxtfwdz, jbgn_jyqk,zrr_xm,yddh,chjidw_dwmc from T_PZ_SYS_SYSTEM " +
				sys.getWheres();
		
		return this.getJdbcTemplate().query(sql, new BeanPropertyRowMapper(ApplicationSystem.class));
	}
	

}
